clear all;close all;clc
% Subject ID: 63, 64, 68, 69, 70, 72, 73, 74, 75, 76, 77, 78, 79, 80
fingers = 'abcde';
finger_names = {'Thumb';'Index';'Middle';'Ring';'Pinky'};
Subjects = {'63', '64', '68', '69', '70', '72', '73', '74', '75', '76', '77', '78', '79', '80','81','82'};
Sessions_all = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20];

% ==================== Plot CM =============================
f1 = figure('position',[100 100 900 900]);
for isubject = 1:length(Subjects)
    Sub = Subjects{isubject}
    file_save = ['Save_EMG_NN_result\' Sub '_CM.mat'];
    load(file_save);
    subplot(4,4,isubject)
    a_finger_test = diag(CM_test)./sum(CM_test)'*100;
    for ifinger=1:5
        pci(ifinger) = f_confid_I(length(Sessions_all)*20,a_finger_test(ifinger)/100,0.05);
    end

    bar(a_finger_test,'facecolor',[0.5 0.5 0.5]);
    hold on;
    errorbar(1:5,a_finger_test,pci*100,'.k');
    set(gca,'XTickLabel',finger_names);
    title(['EMG: S' num2str(isubject)]);
    ylabel('Accuracy (%)');
    ylim([0 100]);
    xlabel('True Finger');
    hold on;
    plot([0 6],[20 20],'k');
    axis square
    box off
    hold off;
    clear CM_test PC_subject;
    pause(0.1)
end
exportgraphics(f1,'Figure4_all_fingers.png','Resolution',300);